package com.rsk.service.curriculum.impl;


import java.util.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.dubbo.config.annotation.Service;
import com.rsk.dao.curriculum.RskCourseRepository;
import com.rsk.dao.extend.curriculum.RskCourseCategoryExtend;
import com.rsk.dao.utils.SearchDataUtils;
import com.rsk.entity.curriculum.RskCourse;
import com.rsk.service.curriculum.RskCourseService;
import com.rsk.utils.algorithm.SnowflakeIdWorker;
import com.rsk.utils.tools.PageUtils;


@Service(interfaceClass = RskCourseService.class)
public class RskCourseServiceImpl implements RskCourseService{
	
	@Autowired
	private RskCourseRepository rskCourseRepository;
	
    @Autowired
    private RskCourseCategoryExtend rskCourseCategoryExtend;
    
    @Autowired
    private SearchDataUtils searchDataUtils;

    @Transactional
	public int saveRskCourse(Long categoryId, String courseName,
			String courseIntroduction, String courseUrl, String courseCover,
			Integer isRecommend, Integer isOriginal, Integer isSee, Integer courseSource, 
			Long operatorUser) {
    	RskCourse rskCourse = new RskCourse();
    	rskCourse.setId(SnowflakeIdWorker.generateId(true));
    	rskCourse.setCategoryId(categoryId);
    	rskCourse.setCourseName(courseName);
		rskCourse.setCourseIntroduction(courseIntroduction);
		rskCourse.setCourseUrl(courseUrl);
		rskCourse.setCourseCover(courseCover);
		rskCourse.setIsRecommend(isRecommend);
		rskCourse.setIsOriginal(isOriginal);
		rskCourse.setCourseStatus(1);
		rskCourse.setIsSee(isSee);
		rskCourse.setAuditStatus(0);
		rskCourse.setIsDel(0);
		rskCourse.setCreateUser(operatorUser);
		rskCourse.setCreateTime(new Date());
		rskCourse.setOperatorUser(operatorUser);
		rskCourse.setOperatorTime(new Date());
		rskCourseRepository.saveAndFlush(rskCourse);
		return 1;
	}

	@Transactional
	public int updateRskCourse(Long id, Long categoryId, String courseName,
			String courseIntroduction, String courseUrl, String courseCover,
			Integer isRecommend, Integer isOriginal, Integer isSee,
			Long operatorUser) {
		RskCourse rskCourse = new RskCourse();
    	rskCourse.setId(id);
    	rskCourse.setCategoryId(categoryId);
    	rskCourse.setCourseName(courseName);
		rskCourse.setCourseIntroduction(courseIntroduction);
		rskCourse.setCourseUrl(courseUrl);
		rskCourse.setCourseCover(courseCover);
		rskCourse.setIsRecommend(isRecommend);
		rskCourse.setIsOriginal(isOriginal);
		rskCourse.setCourseStatus(1);
		rskCourse.setIsSee(isSee);
		rskCourse.setAuditStatus(0);
		rskCourse.setIsDel(0);
		rskCourse.setOperatorUser(operatorUser);
		rskCourse.setOperatorTime(new Date());
		rskCourseRepository.saveAndFlush(rskCourse);
		return 1;
	}
	
	@Transactional
	public int delRskCourse(Long id, Long operatorUser) {
		return rskCourseRepository.delRskCourse(id, operatorUser);
	}

	@Transactional
	public int updateRskCourseStatus(Long id, Integer courseStatus, Long operatorUser) {
		return rskCourseRepository.updateRskCourseStatus(id, courseStatus, operatorUser);
	}

	@SuppressWarnings("rawtypes")
	public PageUtils<Map> selectCourseByPage(String courseName,
			Integer categoryId, Integer isOriginal, Integer isSee,
			Integer isRecommend, Integer courseStatus, Integer nowPage,
			Integer pageSize) {
		return null;
	}

	@Transactional
	public int updateRskCourseRecommend(Long id, Integer isRecommend,
			Long operatorUser) {
		return rskCourseRepository.updateRskCourseRecommend(id, isRecommend, operatorUser);
	}

	@Transactional
	public int updateRskCourseSee(Long id, Integer isSee, Long operatorUser) {
		return rskCourseRepository.updateRskCourseSee(id, isSee, operatorUser);
	}

	
}
